{include file="public/header" /}
<body class="bg-white">
    <div class="rg-userinfo">
        <img src="__STATIC__/plugs/weixin/img/img10.png" alt="">
    </div>
    <form method="post" class="rg-form" id="from">
        <div class="rg-form-item">
            <label for="rg-tel">
                <i class="layui-icon layui-icon-cellphone
                "></i>
            </label>
            <input type="tel" name="phone" id="rg-tel" placeholder="请输入手机号">
            <span class="color-yellow" id="yzm" onclick="sms()">发送验证码</span>
        </div>
        <div class="rg-form-item">
            <label for="rg-pas">
                <i class="layui-icon layui-icon-password
                    "></i>
            </label>
            <input type="password" name="password" id="rg-pas" placeholder="请输入密码">
        </div>
        <div class="rg-form-item">
            <label for="rg-code">
                <i class="layui-icon layui-icon-vercode
                        "></i>
            </label>
            <input type="number" name="code" id="rg-code" placeholder="请输入验证码">
        </div>
        <div class="rg-proto">
            <input type="checkbox" name="xieyi" id="rg-chek" checked>
            <span>注册即表示同意<span class="color-yellow">《零零诉用户协议》</span></span>
        </div>
        <div class="rg-form-item"><button class="order-btn" type="submit">注册</button></div>
    </form>
</body>
<script type="text/javascript">
    //注册
    layui.use(['form'],function () {
        var form = layui.form;
        //二维码获取数据初始化
        $("#from").submit(function (e) {
            e.preventDefault();
            var formzie = $(this).serialize();
            $.post("{:url('/weixin/regist/dologin')}", formzie, function (data) {
                if (data.code == 0) {
                    layer.msg(data.msg)
                } else {
                    layer.msg(data.msg);
                    setTimeout(function () {
                       window.history.back(-1);
                    }, 2000);
                }
            });
        });
    });
    //发送验证码
    var wait = 60;
    function sms() {
        var send = document.getElementById('yzm');
        var phone = $("#rg-tel").val();
        var phoneurl = /^[1][3-9][0-9]{9}/;
        var res = phoneurl.test(phone);
        if (res == false) {
            layer.msg('请输入正确的手机号码');
            return;
        }
        if (wait == 0) {
            send.removeAttribute('disabled');
            send.innerHTML = '免费发送';
            wait = 60;
        } else {
            if (wait == 60) {
                $.getJSON("{:url('/index/sms/phonenull')}?phone=" + phone, function (ret) {
                    if (ret.code == 0) {
                        layer.msg(ret.msg);
                    }
                });
            }
            send.setAttribute('disabled', true);
            send.innerHTML = '（' + wait + '）秒后';
            wait--;
            setTimeout(function () {
                sms();
            }, 1000)
        }
    }
</script>
</html>